package javabasics.netty.login.server.handler;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import javabasics.netty.login.protocol.request.LogoutRequestPacket;
import javabasics.netty.login.protocol.response.LogoutResponsePacket;
import javabasics.netty.login.util.SessionUtil;

/**
 * @Author suxiaoxiao
 * @Date 2019/9/19 23:24
 * @Version 1.0
 */
public class LogoutRequestHandler extends SimpleChannelInboundHandler<LogoutRequestPacket> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, LogoutRequestPacket msg) {
        SessionUtil.unBindSession(ctx.channel());
        LogoutResponsePacket logoutResponsePacket = new LogoutResponsePacket();
        logoutResponsePacket.setSuccess(true);
        ctx.channel().writeAndFlush(logoutResponsePacket);
    }

}
